package cn.edu.scau.cmi.wujingxuan.Factory.AbstractFactory;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class AFClient extends Application
{
	public static GridPane grid;

	@Override
	public void start(Stage stage)
	{
		Text T1 = new Text(250, 50, "姓名：吴敬煊        学号：201627010125");
		Text T2 = new Text(250, 100, "保险公司：");
		Text T4 = new Text(410, 100, "保险类型：");

		ChoiceBox choice1 = new ChoiceBox(FXCollections.observableArrayList("身体受伤", "汽车损坏", "人员伤亡", "多种事故"));
		ChoiceBox choice = new ChoiceBox(FXCollections.observableArrayList("PICC", "PingAn"));

		choice.setLayoutX(320);
		choice.setLayoutY(80);

		choice1.setLayoutX(480);
		choice1.setLayoutY(80);

		Button button = new Button("显示保险信息");
		button.setLayoutX(325);
		button.setLayoutY(120);

		Image my = new Image("IMG_4432.JPG");
		ImageView myIV = new ImageView(my);
		myIV.setFitWidth(100);
		myIV.setFitHeight(150);
		myIV.setX(80);
		myIV.setY(30);

		TextArea T3 = new TextArea();
		T3.setLayoutX(40);
		T3.setLayoutY(200);

		Pane pane = new Pane();
		pane.getChildren().addAll(T1, T2, T3, T4, choice, button, myIV, choice1);
		Scene scene = new Scene(pane, 600, 400);
		stage.setScene(scene);
		stage.setTitle("实验二： 工厂方法");
		stage.show();

		button.setOnAction((ActionEvent e) -> {

			String company = choice1.getValue().toString();
			String type = choice.getValue().toString();
			BuildingFactory bf = BuildingFactory.getBuildingFactory(company);
			String fileNm = null;
			if (type.equals("BodyInjury"))
			{
				BodyInjury bi = bf.getBodyInjury();
				fileNm = bi.getBodyInjurInfo();

			} else if (type.equals("CarDamage"))
			{
				CarDamage cl = bf.getCarDamage();
				fileNm = cl.getCarDamageInfo();

			} else if (type.equals("Casualty"))
			{
				Casualty pi = bf.getCasualty();
				fileNm = pi.getCasualtyInfo();

			} else if (type.equals("Accident"))
			{
				Accident cp = bf.getAccident();
				fileNm = cp.getAccidentInfo();
			}
			T3.setText(fileNm);
		});
	}

	public static void main(String[] args)
	{
		Application.launch(args);
	}
}
